class Command {
    constructor(receiver, action) {
      this.receiver = receiver;
      this.action = action;
    }
  
    execute() {
      this.receiver[this.action]();
    }
  }
  
  class Light {
    on() {
      console.log("The light is ON");
    }
    off() {
      console.log("The light is OFF");
    }
  }
  
  // 测试
  const light = new Light();
  const turnOnCommand = new Command(light, "on");
  const turnOffCommand = new Command(light, "off");
  
  turnOnCommand.execute(); // "The light is ON"
  turnOffCommand.execute(); // "The light is OFF"